<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/11/13
 * Time: 13:40
 */

namespace Modules\Api\Service;

use HiCommon\Repository\ActivityRepository;
use HiCommon\Repository\CouponGrantDetailRepository;
use HiCommon\Repository\CouponsRepository;
use HiCommon\Repository\EquitiesRepository;
use HiCommon\Repository\UsersRepository;
use HiCommon\Repository\UsersLevelRepository;
use HiCommon\Repository\GiftRepository;
use HiCommon\Repository\LogRepository;

class CouponService extends BaseService
{
    /**
     *  发放老用户礼包
     *  hinq 2020 2 29
     *  如果用户是2015年注册的 直到2019年才使用  将只发放最近的年限礼包（3年） ， 2年的礼包将不给予发放
     *
     **/
    public function send_gift_old(){
        //判断礼包是否给予发放（暂不验证）
        $user_info = api_user()->toarray();
        $time1 =  strtotime( $user_info['created_at'] );  //当前用户注册的时间
        $time2 = time() - $time1; //当前时间 - 用户注册时间 = 用户是否是老用户
        $time3 = (int) floor( $time2 / ( 3600 * 24 ) );  //计算得到的是正整数   137.8533 = 137  137.05455 = 137
        if( $time3 < 730 ){  //不满足任何礼包的发放  直接退出     730 = 2(年)  * 365（天/一年按照365天计算）
            return hello_success('没有礼包发放');
        }
        if( $time3  >= 1825 ){  //注册时间大于5年   1825 = 365*5
            return self::send_gift_old_create( (int) 55 , (int) 5 );
        }else if( $time3 >= 1095 && $time3 < 1825 ){  //注册时间大于3年   1095 = 365*3
            return self::send_gift_old_create( (int) 53 , (int) 3 );
        }else if( $time3 >= 730 && $time3 < 1095 ){  //注册时间大于2年   730 = 365*2
            return self::send_gift_old_create( (int) 52 , (int) 2 );
        }
    }

    /**
     *  发放礼包并且记录发放日志
     *  hinq 2020 2 29  骑在银龙的背上
     *  $type  不同年限的礼包55（5年）   53（3年）   52（2年）
     *
     *
     **/
    public function send_gift_old_create( int $type = 55 , int $age = 5 ){

        $user_info = api_user()->toarray();    //用户获取自己的优惠券列表时触发  所有有登录用户信息
        //判断当前用户是否已经发放或次礼包
        $where = ['user_id'=>$user_info['id'], 'type'=> $type ];
        $count = CouponGrantDetailRepository::get_count_by_where( (array) $where );

        if( $count >= 1 ){
            return hello_success('礼包已拥有');
        }
        //# 给用户发放礼包
        $arr_option['field'] = ['id'];
        $arr_option['with'] = ['extend'];
        $arr_option['order'] = ['key'=>'age','value'=>'asc']; 
        $arr_where = ['type'=>2 , 'age'=> $age ];
        //获取指定数据的详细信息
        $arr_list = GiftRepository::get_one_by_where( (array) $arr_where , (array) $arr_option )->toarray();
        if( count( $arr_list ) == 0 ){
            return hello_success('未设置礼包信息');
        }
        $temp['user_id'] = $user_info['id'];      //用户的id
        $temp['msg'] = $age.'年老用户回馈礼包';      //礼包类型名称
        $temp['integral'] = $user_info['integral_all'];  //用户获取礼包时的积分
        $temp['status'] = 1;
        $temp['type'] = $type;   //礼包类型
        $xcq = 0 ; $zkq = 0 ; $mjq = 0; $num = 0;

        foreach ( $arr_list['extend'] as $k => $vo ){
            for ( $i = 1 ; $i <= $vo['number'] ; $i++ ){
                //这里统计不同类型的优惠券发放的数量
                if ($vo['type_coupon'] == 1) {
                    $xcq++;
                } else if ($vo['type_coupon'] == 2) {
                    $mjq++;
                } else if ($vo['type_coupon'] == 3) {
                    $zkq++;
                }
                $num++;  //所有类型的券发放的总量
                $temp['coupon_id'] = $vo['coupon_id'];  //优惠券id
                $temp['pid'] = $vo['type_coupon'];          //优惠券的类型
                $temp['over_at'] = time() + $vo['validity_at'] * 60 * 60 * 24;      //优惠券到期时间
                $temp['ticket_num'] = set_coupons_ticket_num($vo['type_coupon']);   //发放的优惠券券号（唯一）
                $res5 = CouponGrantDetailRepository::add_one( $temp );
            }
        }
        $str = '已发放洗车券：'.$xcq.'张，满减券：'.$mjq.'张，折扣券：'.$zkq.'张,共计发放'.$num.'张';
        $arrlog = [
            'user_id' =>$user_info['id'],      //用户id
            'send_time' => date('Y-m-d H:i:s'),     //发放的时间
            'msg' => $str,      //礼包发放明细说明
            'type' => $type,        //礼包的类型
            'type_msg' => $age.'年老用户回馈礼包'
        ];
        //将发放新用户注册礼包的记录记录日志
        LogRepository::record_send_gift( (array) $arrlog );
        return hello_success('礼包发放成功');
    }



    /**
     *  通过门店分页获取门店下所有的优惠券  一生好短  一瞬好长
     *  hinq 2019 12 31
     *
     **/
    public function get_list_to_shop( array $arr_input ){

        self::send_gift_old();  //每次获取列表数据时都去验证一下当前用户是否需要发放老用户礼包
        $user_id = api_user_id();
        $arr_option['where'] = ['user_id'=>$user_id ];
        $arr_option['with'] = ['shop'];
        $arr_option['field'] = ['shop_id'];
        //分组 分页获取门店信息
        $res = CouponGrantDetailRepository::get_all_view( (array) $arr_input , (array) $arr_option )->toarray();
        $ids = [];
        foreach ( $res['data'] as $key => &$vo ){
            $ids[] = $vo['shop_id'];
            $vo['shop']['logo'] = $vo['shop']['logo']['full_src'];   //店铺logo
        }
        $arr_input['arr_ids'] = $ids;
        $arr_option2['with'] = ['coupon'];
        $arr_option2['where'] = ['user_id'=>$user_id];
        //获取指定门店下所有的优惠券列表信息
        $arr_list = CouponGrantDetailRepository::get_all_view_to_shop( (array) $arr_input , (array) $arr_option2 );
        $coupon_types = ['1'=>'洗车券','2'=>'满减券','3'=>'折扣券'];
        foreach ( $res['data'] as $key => &$value ){
            foreach ( $arr_list->toarray() as $k => &$val ){
                if( $val['shop_id'] == $value['shop_id'] ){
                    $val['over_at'] = date( 'Y-m-j' , $val['over_at'] );   //优惠券过期时间
                    $val['created_at'] = date( 'Y-m-j' ,strtotime( $val['created_at'] ) );    //领取、发放时间
                    if( $val['pid'] == 1 ){
                        $val['remarks'] = $coupon_types[$val['pid']];   //优惠券说明
                    }else if( $val['pid'] == 2 ){
                        $val['remarks'] = '满'.(string) floatval($val['coupon']['price_all']).'元减'.(string) floatval($val['coupon']['price']).'元';
                    }else if( $val['pid'] == 3 ){
                        $val['remarks'] = '满'.(string) floatval( $val['coupon']['price_all'] ).'元打'.$val['coupon']['discount_num'].'折';
                    }
                    $val['pid_msg'] = $coupon_types[$val['pid']];       //优惠券类型说明
                    $val['price_all'] = (string) floatval( $val['coupon']['price_all'] );       //优惠券最低使用金额
                    $val['price'] = (string) floatval( $val['coupon']['price'] );       //优惠金额
                    $val['discount_num'] = (string) floatval( $val['coupon']['discount_num'] );     //折扣数量
                    $val['name'] = $val['coupon']['name'];      //优惠券名称
                    $val['content'] = $val['coupon']['content'];        //优惠券使用、规则说明
                    unset( $val['coupon'] );
                    $value['coupon'][] = $val;
                    unset( $val );
                }
            }
            unset($value['shop_id']);
        }
        $arr_list = [
            'page'=>[
                'current_page'=>$res['current_page'],
                'last_page'=>$res['last_page'],
                'per_page'=>$res['per_page'],
                'total'=>$res['total'],
            ],
            'data'=>$res['data'],
        ];
        return hello_success('ok',$arr_list);


    }

    /**
     *  通过用户分组获取所有的优惠券列表
     *  hinq 2019 11 13
     *
     **/
    public function get_list( array $arr_input ){
        try{
            $user_id = api_user_id();
            $arr_option['where'] = ['user_id'=>$user_id ];
            $arr_option['with'] = ['getCouponInfoAll','getCouponInfoAll.shop'];
            $arr_option['order'] = ['key'=>'status','value'=>'asc'];
            $arr_option['field'] = ['id','user_id','coupon_id','pid','over_at','ticket_num','msg','integral','status','created_at'];
            $res = CouponGrantDetailRepository::get_list( (array) $arr_input , (array) $arr_option )->toArray();
            $coupon_types = ['1'=>'洗车券','2'=>'满减券','3'=>'折扣券'];
            //通过条件获取所有有效的数据， 处理数据 字段信息的处理
            foreach ($res['data'] as $key => &$value) {
                $value['get_coupon_info_all']['discount_num'] = floatval($value['get_coupon_info_all']['discount_num']);
                $value['get_coupon_info_all']['price'] = floatval($value['get_coupon_info_all']['price']); //保留有效的小数位
                $value['over_at'] = date( 'Y-m-j' , $value['over_at'] );
                $value['pid_msg'] = $coupon_types[$value['pid']];
                if( $value['pid'] == 1 ){
                    $value['remarks'] = $coupon_types[$value['pid']];
                }else if( $value['pid'] == 2 ){
                    $value['remarks'] = '满'.intval($value['get_coupon_info_all']['price_all']).'元减'.$value['get_coupon_info_all']['price'].'元';
                }else if( $value['pid'] == 3 ){
                    $value['remarks'] = '满'.intval( $value['get_coupon_info_all']['price_all'] ).'元打'.$value['get_coupon_info_all']['discount_num'].'折';
                }
                $value['created_at'] = date( 'Y-m-j' ,strtotime( $value['created_at'] ) );
                $logo = $value['get_coupon_info_all']['shop']['logo']['full_src'];
                $value['get_coupon_info_all']['shop']['logo'] = $logo;
            }
            //处理数据  将相同门店下的数据存放到一个数组中
            $temp = [];
            foreach ( $res['data'] as &$item ){
                $temp[$item['get_coupon_info_all']['shop']['id']]['company'] = $item['get_coupon_info_all']['shop'];
                $temp[$item['get_coupon_info_all']['shop']['id']]['coupons'][] = $item;
            }
            //处理数据  重新整理数据格式方便前端调用
            $temps = [];
            foreach ( $temp as $key=>$item ){
                $temps[] = $item;
            }
            $arr_list = [
                'page'=>[
                    'current_page'=>$res['current_page'],
                    'last_page'=>$res['last_page'],
                    'per_page'=>$res['per_page'],
                    'total'=>$res['total'],
                ],
                'data'=>$temps,
            ];
            return hello_success('ok',$arr_list);
        }catch ( \Exception $exception ){
            return ['state'=>1,'msg'=>$exception->getMessage()];
        }
    }

    /**
     *	获取优惠券详情数据
     *	hinq 2019 09 10
     *
     **/
    public function detail( int $nId ){
        try{
            if( empty( $nId ) ){
                return ['state'=> 1,'msg'=>'参数错误','data'=>[],'error'=>''];
            }
            $arr_where['with'] = ['getCouponInfo'];
            $res = CouponGrantDetailRepository::get_one( (int) $nId , (array) $arr_where );
            if( empty( $res->first() ) ){
                return hello_success('参数错误');
            }
            $result = hi_check_res($res,'get_one');
            if ($result['state'] != 0) {
                return ['state'=> 1,'msg'=>'获取失败','data'=>[],'error'=>''];
            }

            $data['ticket_num'] = $res['ticket_num'];
            $data['content'] = $res['getCouponInfo']['content'];
            $data['coupon_id'] = $res['coupon_id'];
            $data['pid'] = $res['pid'];

            return ['state'=> 0,'msg'=>'ok','data'=>$data,'error'=>''];
        } catch (\Exception $exception) {
            return ['state'=>1,'msg'=>$exception->getMessage()];
        }
    }


    /**
     *	会员升级发放会员等级礼包
     *	hinq 2019 09 26
     *	先将用户获得的积分更新到数据库中在调用此接口
     **/
    public function send_upgrade_material_benefits( int $nId ){

        try{
            if( empty( $nId ) ){
                return ['state'=> 1,'msg'=>'用户id不能为空','data'=>[],'error'=>''];
            }
            //获取用户的积分信息
            $user_info = UsersRepository::get_one( (int) $nId , (array) ['field'=>['id','integral','integral_all']]);

            //获取会员等级列表
            $user_level = UsersLevelRepository::get_all( (array) ['order'=>['key'=>'min_integral' ,'value'=>'asc'] ,'field'=>['id','name','min_integral','max_integral','equities']]);

            $user_new_level = [];  //会员所属的会员等级
            //检测当前用户会员等级
            foreach ($user_level->toArray() as $key => $value) {
                //      会员当前的总积分         >=      会员等级的最低积分      会员当前的总积分          <=     会员等级的最大积分
                if( $user_info['integral_all'] >= $value['min_integral'] && $user_info['integral_all'] <= $value['max_integral']){
                    $user_new_level = $value;  //获取当前会员所属的会员等级
                }
            }
            //获取当前所属等级的所有权益
            $equities_ids = explode(',', $user_new_level['equities'] );  //当前等级的所有权益
            $level_equities = EquitiesRepository::get_all_by_whereIn( (array) $equities_ids , (array) ['with'=>['get_equities']] );
            $coupon_list = [];  //权益的优惠券礼包集合
            foreach ($level_equities->toArray() as $key => $value) {
                if( count( $value['get_equities'] ) > 0 ){
                    //获取需要发放的优惠券数据
                    foreach ($value['get_equities'] as $k => $val) {
                        //升级时一次性优惠券 和每月固定的优惠券 在会员升级时都发放一次
                        $coupon_list['coupon'][] = $val['coupon_id'];
                        $coupon_list['num'][] = $val['num'];
                        $coupon_list['equities'][] = $value['id'];
                    }
                }
            }

            if( count( $coupon_list ) <= 0 ){
                return ['state'=> 0,'msg'=>'暂无礼包发放','data'=>[],'error'=>''];
            }

            //获取权益礼包中包含的所有优惠券信息
            $coupon = CouponsRepository::get_all_by_whereIn( (array) array_unique($coupon_list['coupon'] ) ,(array)['field'=>['id','pid','validity_at']]);
            $coupon_pids = [];
            foreach ($coupon as $key => $value) {
                $coupon_pids[$value['id']]['pid'] = $value['pid'];
                $coupon_pids[$value['id']]['validity_at'] = $value['validity_at'];
            }

            //检测当前用户是否已经发放过升级礼包
            foreach ($coupon_list['coupon'] as $key => $value) {
                $arr_map['user_id'] = $nId;
                $arr_map['coupon_id'] = $value;
                $arr_map['type'] = 1;
                $arr_map['user_level'] = $user_new_level['id'];
                $arr_map['equities'] = $coupon_list['equities'][$key];
                //升级礼包是一起发放的 如果有发放过升级礼包所有的礼包都不发放 否则发放
                if( CouponGrantDetailRepository::get_count_by_where( (array) $arr_map ) >= 1){
                    return ['state'=> 0,'msg'=>'升级礼包已发放，请勿重复发放','data'=>[],'error'=>''];
                }
                $temp['user_id'] = $nId;
                $temp['coupon_id'] = $value;
                $temp['msg'] = '会员升级发放会员等级礼包';
                $temp['integral'] = $user_info['integral_all'];
                $temp['status'] = 1;
                $temp['type'] = 1;
                $temp['user_level'] = $user_new_level['id'];
                $temp['equities'] = $coupon_list['equities'][$key];

                for ($i=1; $i <= $coupon_list['num'][$key] ; $i++) {
                    $temp['pid'] = $coupon_pids[$value]['pid'];
                    $temp['over_at'] = $coupon_pids[$value]['validity_at'] * 3600 * 24 + time();
                    $temp['ticket_num'] = set_coupons_ticket_num( $coupon_pids[$value]['pid'] );
                    $res = CouponGrantDetailRepository::add_one( $temp );
                    $result = hi_check_res($res,'edit_one');
                    if ($result['state'] != 0) {
                        return ['state'=> 1,'msg'=>'升级礼包发放失败','data'=>[],'error'=>''];
                    }
                }
            }
            return ['state'=> 0,'msg'=>'ok','data'=>[],'error'=>''];
        } catch (\Exception $exception) {
            return ['state'=>1,'msg'=>$exception->getMessage()];
        }

    }


    /**
     *  商城下订单时获取有效的优惠券   你知道闻香玉吗
     *  hinq 2019 12 16
     *  通过订单信息（门店id 、 商品价格） 获取当前门店下所有的优惠券
     **/
    public function my_coupon_to_goods( array $arr_input ){
        try{
            //当前订单的价格
            $goods_price = $arr_input['price'];     //当前购买商品的价格
            $shop_id = $arr_input['shop_id'];       //当前订单所属的门店
            if( !empty( $shop_id ) && $shop_id != 1 ){  //如果是门店  门店需要获取平台的优惠券
                $shop_id = [1, (int) $shop_id];
            }else{      //如果是平台  只能获取平台的优惠券  1：代表平台
                $shop_id = [1];
            }
            //获取当前用户的所有领取并且未使用的优惠券
            $data['shop_id'] = $shop_id;
            $data['type'] = $arr_input['type'];
            $arr_option['where'] = ['user_id'=>api_user_id(),'status'=>1];   //当前用户   未使用状态
            $arr_option['with'] = ['coupon_info'=>function($query)use($data){
                $query->whereIn('repairstore_id', $data['shop_id'] )->where(['type'=>$data['type']]);
            }]; //这里关联了优惠券主表，只能使用当前店铺和平台发布的优惠券 ， A维修店不可以使用B维修店发布的优惠券
            $arr_option['field'] = ['id','coupon_id','pid','ticket_num','over_at','created_at'];
            $arr_list = CouponGrantDetailRepository::get_all_to_goods( (array) $arr_option );  //获取所有领取的优惠券
            if( empty( $arr_list->first() ) ){
                return hello_success('ok',[]);
            }
            $arr_list = $arr_list->toarray();

            $coupon_types = ['1'=>'洗车券','2'=>'满减券','3'=>'折扣券'];  //李淳风
            foreach ( $arr_list as $key => $value ){
                if( empty( $value['coupon_info'] ) ){ //  如果coupon_info为空 说明该领取的优惠券不属于门店的  因为领取表没有关联门店信息 一次过滤不掉
                    unset( $arr_list[$key] );
                }
                //     当前优惠券的总价格   >    当前商品的价格   相等的时候也是可以使用的
                if( $value['coupon_info']['price_all'] >  $goods_price ){
                    unset( $arr_list[$key] );
                }
            }
            $data = [];
            foreach ( $arr_list as $key => $value ){
                $data[$key]['id'] = $value['id'];
                $data[$key]['name'] = $value['coupon_info']['name'];
                $data[$key]['coupon_id'] = $value['coupon_id'];
                $data[$key]['pid'] = $value['pid'];
                $data[$key]['pid_name'] = $coupon_types[$value['pid']];
                $data[$key]['price_all'] = (string) floatval( $value['coupon_info']['price_all'] );
                $data[$key]['price'] = (string) floatval( $value['coupon_info']['price'] );
                $data[$key]['discount_num'] = (string) floatval( $value['coupon_info']['discount_num'] );
                $data[$key]['start_at'] = date('Y-m-d' , strtotime( $value['created_at'] ) );
                $data[$key]['over_at'] = date('Y-m-d',$value['over_at']);
                if( $value['pid'] == 2 ){
                    $data[$key]['msg'] = '满'. (string) floatval( $value['coupon_info']['price_all'] ) . '减' . (string) floatval( $value['coupon_info']['price'] );
                }else{
                    $data[$key]['msg'] = '满'. (string) floatval( $value['coupon_info']['price_all'] ) . '折扣' . (string) floatval( $value['coupon_info']['discount_num'] );
                }
            }
            return hello_success('ok' , array_values($data) );
        }catch ( \Exception $exception ){
            return ['state'=>1,'msg'=>$exception->getMessage()];
        }
    }



    /**
     *	订单详情页获取指定门店下所有的优惠券【门店可以获取平台的优惠券 ， 平台只能获取平台的优惠券】
     *	hinq 2019 12 13
     *	int  shop_id    门店id
     *
     **/
    public function my_coupon_to_shop( array $arr_input ){
        try{
            if( empty( $arr_input['shop_id'] ) ){
                return hello_error('参数错误');
            }
            if( $arr_input['shop_id'] == 1 ){  //  平台   平台只能获取平台的优惠券
                $repairstore_ids = [1];
            }else{   //门店
                $repairstore_ids = [1 , $arr_input['shop_id'] ];
            }
            //获取指定门店下所有有效的满减、折扣券
            $arr_option['where'] = ['status'=>1 , 'type'=>$arr_input['type'] ];
            $arr_option['field'] = ['id','name','price','discount_num','price_all','ticket_num','pid'];
            if( !empty( api_user_id() ) ){   //有用户登录
                $arr_option['with'] = ['counttogoods'];  //判断用户是否已经领取过当前优惠券
            }
            $arr_list = CouponsRepository::get_all_whereIn_shop_id( (array) $repairstore_ids , (array) $arr_option );
            if( empty( $arr_list->first() ) ){
                return hello_success('ok',[]);
            }
            $arr_list = $arr_list->toArray();
            $coupon_types = ['1'=>'洗车券','2'=>'满减券','3'=>'折扣券'];
            foreach ( $arr_list as $key => &$vo ){
                $vo['is_get'] = false;
                if( isset( $vo['counttogoods'] ) && !empty( $vo['counttogoods'] ) ){
                    $vo['is_get'] = true;
                }
                unset( $vo['counttogoods'] );
                $vo['discount_num'] = (string) floatval( $vo['discount_num'] );
                $vo['price'] = (string) floatval( $vo['price'] );
                $vo['price_all'] = (string) floatval( $vo['price_all'] );
                $vo['pid_name'] =  $coupon_types[$vo['pid']];
                if( $vo['pid'] == 2 ){
                    $vo['msg'] = '满'. (string) floatval( $vo['price_all'] ) . '减' . (string) floatval( $vo['price'] );
                }else{
                    $vo['msg'] = '满'. (string) floatval( $vo['price_all'] ) . '折扣' . (string) floatval( $vo['discount_num'] );
                }
            }
            return hello_success('ok',$arr_list);
        }catch ( \Exception $exception ){
            return ['state'=>1,'msg'=>$exception->getMessage()];
        }
    }

    /**
     *  领取商品订单的详情的优惠券
     *  hinq 2019 12 13
     *
     **/
    public function coupon_to_shop_store( array $arr_input){
        try{
            if( empty( $arr_input['coupon_id'] ) ){
                return hello_error('参数错误');
            }
            //获取指定优惠券的信息
            $arr_option['field'] = ['pid','validity_at','repairstore_id'];
            $arr_list = CouponsRepository::get_one( (int) $arr_input['coupon_id'] , (array) $arr_option );
            if( empty( $arr_list ->first() ) ){
                return hello_error('参数错误');
            }


            $arr_list = $arr_list->toarray();

            //当前登录的用户
            $user_info = api_user();

            //获取当前用户是都已经领取过优惠券
            $where['user_id'] = $user_info['id'];
            $where['coupon_id'] = (int) $arr_input['coupon_id'];
            $where['type'] = 3;     //类型  1：普通商品   2：服务商品  3：保养套餐
            $where['status'] = 1;
            $count = CouponGrantDetailRepository::get_count_by_where( (array) $where );  //当前用户是否已经领取了优惠券
            if( $count > 0 ){
                return hello_error('您已经领取了优惠券');
            }

            //领取需要添加的数据
            $data['user_id'] = $user_info['id'];     //用户id
            $data['coupon_id'] = $arr_input['coupon_id'];       //优惠券id
            $data['pid'] = $arr_list['pid'];                //优惠券的类型
            $data['over_at'] = time() + 3600 * 24 * $arr_list['validity_at'];    //优惠券有效期
            $data['ticket_num'] = set_coupons_ticket_num( $arr_list['pid'] );    //优惠券的券号
            $data['msg'] = '用户主动领取优惠券';
            $data['integral'] = $user_info['integral'];      //用户当前的剩余积分
            $data['status'] = 1;
            $data['type'] = 3;          //类型  1：普通商品   2：服务商品  3：保养套餐
            $res = CouponGrantDetailRepository::add_one( (array) $data );
            if( empty( $res ) ){
                return hello_error('参数错误');
            }
            return hello_success('ok');
        }catch ( \Exception $exception ){
            return ['state'=>1,'msg'=>$exception->getMessage()];
        }
    }
}